package com.xsmart.order.api.wx;

import com.xsmart.common.entity.RequestBean;
import com.xsmart.common.entity.ResponseBean;
import com.xsmart.order.services.ShoppingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * 微信接口
 *
 * @author guojd
 */
@RestController
@RequestMapping("/api")
public class WxOrderController {

    /**
     * 购物车
     */
    @Autowired
    ShoppingService shoppingService;

    /**
     * 添加购物车
     *
     * @param requestBean 请求对象
     *                    uid:用户id
     *                    pid:商品id
     *                    num:商品数量
     * @param request     请求对象
     * @return 商品详情
     */
    @PostMapping(value = "/v1/WxOrderController/addShopping")
    public ResponseBean addShopping(@ModelAttribute RequestBean requestBean, HttpServletRequest request) {
        return shoppingService.addShopping(requestBean);
    }

    /**
     * 会员获取购物车列表
     *
     * @param requestBean 请求对象
     *                    uid:用户id
     * @param request     请求对象
     * @return 商品详情
     */
    @PostMapping(value = "/v1/WxOrderController/shoppingList")
    public ResponseBean shoppingList(@ModelAttribute RequestBean requestBean, HttpServletRequest request) {
        return shoppingService.shoppingList(requestBean);
    }

    /**
     * 更新购物车数量
     *
     * @param requestBean 请求对象
     *                    rec_id:购物车id
     *                    num:商品数量
     *                    uid：用户id
     * @param request     请求对象
     * @return 成功失败
     */
    @PostMapping(value = "/v1/WxOrderController/updateCartGoodsNumber")
    public ResponseBean updateCartGoodsNumber(@ModelAttribute RequestBean requestBean, HttpServletRequest request) {
        return shoppingService.updateCartGoodsNumber(requestBean);
    }

    /**
     * 删除购物车数量
     *
     * @param requestBean 请求对象
     *                    rec_id:购物车id
     * @param request     请求对象
     * @return 成功失败
     */
    @PostMapping(value = "/v1/WxOrderController/delCart")
    public ResponseBean delCart(@ModelAttribute RequestBean requestBean, HttpServletRequest request) {
        return shoppingService.delCart(requestBean);
    }

    /**
     * 购物车结算 获取数据
     *
     * @param requestBean 请求对象
     *                    cart_id:购物车id，多个采用"，"分隔
     *                    uid:用户ID
     * @param request     请求对象
     * @return 成功失败
     */
    @PostMapping(value = "/v1/WxOrderController/buyCart")
    public ResponseBean buyCart(@ModelAttribute RequestBean requestBean, HttpServletRequest request) {
        return shoppingService.buyCart(requestBean);
    }

    /**
     * 购物车结算 获取数据
     *
     * @param requestBean 请求对象
     *                    uid: 用户ID
     *                    cart_id: 购物车id，多个采用"，"分隔
     *                    type: 支付类型
     *                    aid: 地址的id
     *                    remark: 用户备注
     *                    price: 总价
     *                    vid: 优惠券ID
     * @param request     请求对象
     * @return 成功失败
     */
    @PostMapping(value = "/v1/WxOrderController/createOrder")
    public ResponseBean createOrder(@ModelAttribute RequestBean requestBean, HttpServletRequest request) {
        return shoppingService.createOrder(requestBean);
    }

    /**
     * 从商品详情页立即购买
     * @param requestBean 请求对象
     * @param request
     * @return
     */
    @PostMapping(value = "/v1/WxOrderController/buyNow")
    public ResponseBean buyNow(@ModelAttribute RequestBean requestBean, HttpServletRequest request) {
        return shoppingService.buyNow(requestBean);
    }

}
